<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../../res/js/jquery-3.1.1.min.js"></script>
    <script src="../../../res/layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../../res/js/urltools.js" charset="utf-8"></script>
</head>
<body style="padding: 10px">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>分公司信息</legend>
</fieldset>

<form class="layui-form" name="myform" method="post" lay-filter="myform" id="myform" enctype="multipart/form-data">
    <input type="hidden" name="immId" id="immId">

    <div class="layui-form-item">
        <label class="layui-form-label">分公司名称</label>
        <div class="layui-input-block">
            <input id="immName" type="text" name="immName" lay-verify="required" maxlength="20" autocomplete="off" placeholder="请输入分公司名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否有效</label>
        <div class="layui-input-block">
            <input type="radio" name="isva" id="isva" value="1" title="有效" checked="checked" >
            <input type="radio" name="isva" id="isva" value="0" title="无效">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">金额</label>
        <div class="layui-input-block">
            <input id="ifnanceMoney" type="text" name="ifnanceMoney" lay-verify="required" maxlength="8" autocomplete="off" placeholder="请输入金额" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input id="remark" type="text" name="remark" autocomplete="off" placeholder="备注" maxlength="20" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="submit" class="layui-btn" lay-submit="" lay-filter="add" value="立即提交">
        </div>
    </div>

</form>

<script>

    //全局同步
    $.ajaxSetup({
        async: false
    });

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,$ = layui.$;


        //监听提交
        form.on('submit(add)', function(data){
            var url='../../../hqImm/addORupdate';
            //将表单中的所有元素转换成二进制流
            var formData=data.field;
            console.info(formData);
            $.post(url,formData,function(resp){
                if(resp.status > 0){
                    parent.layui.table.reload("testReload");
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            },"json")
            return false;
        });

        //表单赋值
        var immId = getQueryString("immId");
        if(immId){
            console.info(immId);
            var url = "../../../hqImm/queryById";
            var data = {id:immId};
            $.post(url,data,function(obj){
                console.info(obj);
                form.val('myform',obj);
            },"json");
        };

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });

</script>

</body>
</html>